pluginHome = new File("./plugins").listFiles().find { it.name.startsWith('cloud-tools-')}
if(pluginHome == null) pluginHome = "."

includeTargets << new File( "${pluginHome}/scripts/CloudToolsInit.groovy" )

target('default': "Add another appserver") {
	depends( initCloudToolsService)
   	addAppServers()
}

target(addAppServers: "The implementation task") {
	
	def numberOfServers = "1"
	//making a string because when this value is read from the command line it will come in as a string... simplifies the code below
	cloudToolsService.withCluster { clusterManager, clusterName, cluster ->
		if(System.getProperty("cloudtools.newAppServers")){
			numberOfServers = System.getProperty("cloudtools.newAppServers")
		}
        cluster.getClusterInstance().addAppServers(Integer.parseInt(numberOfServers));
	    clusterManager.saveCluster(clusterName, cluster);
		event('StatusFinal', ["Finished adding $numberOfServers server(s)"])
    }
}